<template>
  <div class="produce-model-dialog">
    <el-dialog v-model="drawerVisibleDetail" :destroy-on-close="true" :title="`产品信息`" width="96%" draggable align-center>
      <el-scrollbar height="100%" :native="true">
        <div class="produce-model">
          <div class="produce-model-item mt30" v-for="(item, index) in detailData" :key="`cs_${index}`">
            <div class="produce-model-item-title">
              <span class="b-f">{{ item.name }}</span>
            </div>
            <div class="produce-model-item-content" v-if="[1, 4, 5, 8].includes(item.type)">
              <div class="group-item" v-for="(itm, idx) in item.children" :key="`${idx}_${item.id}`">
                <span>{{ itm.title }}</span>
                <span v-if="!itm.type">
                  <template v-if="Array.isArray(itm.value)">
                    <i v-for="(val, i) in itm.value" :key="i + 'sfr'">{{ val }}</i>
                  </template>
                  <i v-else>{{ itm.value }}</i>
                </span>
                <span v-else>
                  <a @click="imageHandle(itm.value)" style="cursor: pointer">{{ !itm.value ? "--" : "查看" }}</a>
                </span>
              </div>
            </div>
            <div v-if="[2, 7].includes(item.type)">
              <ul class="group-image">
                <li
                  v-for="(itm, idx) in item.children"
                  :key="`${idx}_${item.id}`"
                  @click="() => (itm.path.match(/.*\.mp4$/i) ? '' : imageHandle(itm.path))"
                >
                  <div class="image-video" :custom="itm.path">
                    <video v-if="itm.path.match(/.*\.mp4$/i)" width="100%" height="100%" controls preload="none">
                      <source :src="itm.path" type="video/mp4" />
                    </video>
                    <img v-else :src="itm.path" alt="" />
                  </div>
                  <span class="text">{{ itm.remark }}</span>
                </li>
              </ul>
            </div>
            <div class="group-map" v-if="item.type === 3">
              <div class="group-map-left">
                <div class="group-item" v-for="(itm, idx) in item.children" :key="`${idx}_${item.id}`">
                  <span>{{ itm.title }}</span>
                  <span v-if="!itm.type">
                    <template v-if="Array.isArray(itm.value)">
                      <i v-for="(val, i) in itm.value" :key="i + 'sfr'">{{ val }}</i>
                    </template>
                    <i v-else>{{ itm.value }}</i>
                  </span>
                  <span v-else>
                    <a @click="imageHandle(itm.value)" style="cursor: pointer">{{ !itm.value ? "--" : "查看" }}</a>
                  </span>
                </div>
              </div>
              <div class="group-map-right">
                <Map :lng="item.lng" :lat="item.lat" />
              </div>
            </div>
            <div v-if="item.type === 6">
              <ul class="group-video">
                <li v-for="(itm, idx) in item.children" :key="`${idx}_${item.id}`">
                  <video width="100%" height="100%" controls preload="none">
                    <source :src="itm.path" type="video/mp4" />
                  </video>
                  <div class="group-video-title">{{ itm.remark }}</div>
                </li>
              </ul>
            </div>
            <div class="group-other" v-if="item.type === 9">
              <div class="group-item" v-for="(itm, idx) in item.children" :key="`${idx}_${item.id}`">
                <span>{{ itm.value }}</span>
                <!-- <span>{{ itm.title }}</span> -->
                <!-- <span v-if="!itm.type">
                  <template v-if="Array.isArray(itm.value)">
                    <i v-for="(val, i) in itm.value" :key="i + 'sfr'">{{ val }}</i>
                  </template>
                  <i v-else>{{ itm.value }}</i>
                </span> -->
                <!-- <span v-else>
                  <a @click="imageHandle(itm.value)" style="cursor: pointer">{{ !itm.value ? "--" : "查看" }}</a>
                </span> -->
              </div>
            </div>
          </div>
        </div>
      </el-scrollbar>
    </el-dialog>
    <el-image-viewer v-if="imgViewVisible" :url-list="[`${url}`]" @close="imgViewVisible = false" />
  </div>
</template>

<script setup lang="ts">
import { ref } from "vue";
import { useDetail } from "./hooks/useDetail";
import Map from "./Map/index.vue";
// import { useDict } from "@/hooks/useDict";
const drawerVisibleDetail = defineModel("drawerVisibleDetail", {
  type: Boolean,
  default: false
});
const props = defineProps({
  id: {
    type: String,
    default: ""
  }
});
const imgViewVisible = ref(false);
const url = ref("");
// hook
const { detailData } = useDetail({ id: props.id });
// const { getDictItem } = useDict(["productId"]);
// 方法
const imageHandle = val => {
  if (!val) return;
  imgViewVisible.value = true;
  url.value = val;
};
// const setInfo = (data: string) => {
//   return data || "--";
// };
</script>
<style lang="scss" scoped>
ul,
li {
  padding: 0;
  margin: 0;
  list-style: none;
}
.b-f {
  font-size: 16px;
  font-weight: 600;
  color: #333333;
}
.b-t {
  font-size: 16px;
  font-weight: 400;
  color: #999999;
}
.b-c {
  font-size: 14px;
  font-weight: 400;
  color: #333333;
}
.produce-model {
  height: 70vh;
  padding: 10px 40px 40px;
  will-change: transform;
  &-item {
    border: 1px solid #f3f3f3;
    &-title {
      box-sizing: border-box;
      height: 60px;
      padding: 20px;
      font-size: 14px;
      font-weight: 600;
      color: #333333;
      border-bottom: 1px solid #f3f3f3;
    }
    &-content {
      display: grid;
      grid-template-columns: repeat(3, 1fr);
      .group-item:nth-child(3n) {
        // border-right: none;
        border-left: none;
      }
      .group-item:nth-child(2n) {
        // border-right: none;
        border-left: none;
      }
    }
  }
  .group-item {
    box-sizing: border-box;
    display: flex;
    align-items: center;
    height: 64px;
    border: 1px solid #f3f3f3;
    border-top: none;
    span:first-child {
      box-sizing: border-box;
      width: 100%;
      height: 100%;
      padding: 0 20px;
      line-height: 64px;
      text-align: right;
      background: #f7fcfe;
      border-right: 1px solid #f3f3f3;
    }
    a {
      color: $primary-color;
      cursor: pointer;
    }
    span:last-child {
      box-sizing: border-box;
      display: flex;
      flex-flow: column nowrap;
      justify-content: center;
      width: 100%;
      height: 100%;
      padding: 0 20px;
      overflow: auto;
      font-size: 14px;
      font-weight: 400;
      line-height: 20px;
      color: #333333;
      text-align: left;
      i {
        font-style: normal;
        text-align: left;
      }
    }
  }
  .group-image {
    box-sizing: border-box;
    display: grid;
    grid-template-columns: repeat(auto-fill, 240px);
    gap: 40px;
    width: 0;
    width: 100%;
    padding: 50px;
    border-right: 1px solid #f3f3f3;
    border-left: 1px solid #f3f3f3;
    li {
      display: flex;
      flex-flow: column nowrap;
      .image-video {
        width: 240px;
        height: 240px;
        img {
          width: 100%;
          height: 100%;
          object-fit: contain;
        }
      }
      .text {
        margin-top: 20px;
        font-size: 16px;
        color: #666666;
        text-align: center;
      }
    }
  }
  .group-video {
    box-sizing: border-box;
    display: grid;
    grid-template-columns: repeat(auto-fill, 240px);
    gap: 40px;
    width: 0;
    width: 100%;
    padding: 50px;
    border-right: 1px solid #f3f3f3;
    border-left: 1px solid #f3f3f3;
    li {
      display: flex;
      flex-flow: column nowrap;
      video {
        width: 240px;
        height: 240px;
        object-fit: contain;
      }
      .group-video-title {
        box-sizing: border-box;

        // height: 105px;
        padding-top: 10px;
        overflow: hidden;
        text-align: center;
        word-break: break-all;
        white-space: nowrap;
      }
    }
  }
  .group-map {
    display: grid;
    grid-template-columns: 1fr 2fr 0fr;
    &-left {
      display: flex;
      flex-flow: column nowrap;
    }
  }
  .group-other {
    display: flex;
    flex-flow: column nowrap;
    .group-item {
      display: grid;
      grid-template-columns: 1fr;
      height: auto;
      padding: 20px 0;
      background: #ffffff;
      span {
        background: #ffffff;
      }
    }

    // .group-item:last-child {
    //   height: 225px;
    //   span {
    //     height: 100%;
    //     line-height: 225px;
    //   }
    // }
  }
}
</style>
